# _*_ coding:utf-8 _*_
# 下载器模块
# 根据请求对象,发送请求获取响应数据,封装Response对象返回
import requests
from ..http.response import Response


class Downloder(object):
    def get_response(self, request):

        # 根据请求对象,发送请求获取响应数据,封装Response对象返回
        if request.method.upper() == "GET":

            resp = requests.get(request.url, headers=request.headers, params=request.params, cookies=request.cookies)

            # res =  requests.get(request.url, headers=request.headers, params=request.params, cookies=request.cookies)

        elif request.method.upper() == "POST":

            resp = requests.post(request.url, headers=request.headers,data=request.data, cookies=request.cookies)

        else:
            raise Exception("暂时仅支持get,post请求")
        # 返回封装后的响应数据
        return Response(resp.url, resp.status_code, resp.headers, resp.content)
